//引入 pinia插件
import { defineStore } from "pinia";
//引入vue文件
import { ref } from "vue";
//引入数据类型
import type { userInfoResult } from '@/types/user'

//导出token
export const useUserStore = defineStore("user", () => {

	//token信息
	const userInfo = ref<userInfoResult>();
	//保存token信息
	const setUserInfo = (val : userInfoResult) => {
		userInfo.value = val;
	}

	//清空token信息
	const clearUserInfo = () => {
		userInfo.value = undefined;
	}

	//返回数据
	return { userInfo, setUserInfo, clearUserInfo };

},
	//持久化
	{
		persist: {
			storage: {
				getItem(key) {
					return uni.getStorageSync(key);
				},
				setItem(key, value) {
					uni.setStorageSync(key, value);
				}
			}
		}
	}

)